/*This is a program that runs the Windows CMD and executes commands
 * Returning the result to Java.  Right now I have the program set
 * to return the System Info (cmd /c systeminfo).
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class CommandControl
{
	ArrayList output = new ArrayList();
	
	protected void executeCommand(final String str, boolean needRead)
	{
		try
		{
			Process program = Runtime.getRuntime().exec(str);
			if (needRead == true)
			{
				readCommand(program.getInputStream());
			}
		}
		catch (IOException e) { e.printStackTrace(); }
	}
	
	public void readCommand(InputStream input)
	{
		ArrayList temp = new ArrayList();
		try
		{
			BufferedReader reader = new BufferedReader(new InputStreamReader(input));
			String str = "";
			while ((str = reader.readLine()) != null)
			{
				temp.add(str);
			}
		}
		catch(IOException e) { e.printStackTrace(); }
		setOutput(temp);
	}
	
	protected void setOutput(ArrayList output)
	{
		this.output = output;
	}
	
	public void inputCommand(String cmd, boolean bol)
	{
		//cmd = "cmd /c tasklist";
		executeCommand(cmd, bol);
	}

}
